<?php
function gettestnum($catid){
    global $db;
    $num = $db->get_one("SELECT COUNT(*) AS num FROM `".DB_PRE."test` WHERE `catid`=$catid");
    return $num[num];
}
    
function set_config($config)
{
	if(!is_array($config)) return FALSE;
	$configfile = KS_ROOT.'/inc/config.inc.php';
	if(!is_writable($configfile)) showmessage('Please chmod ./inc/config.inc.php to 0777 !');
	$pattern = $replacement = array();
	foreach($config as $k=>$v)
	{
		$pattern[$k] = "/define\(\s*['\"]".strtoupper($k)."['\"]\s*,\s*([']?)[^']*([']?)\s*\)/is";
        $replacement[$k] = "define('".$k."', \${1}".$v."\${2})";
	}
	$str = file_get_contents($configfile);
	$str = preg_replace($pattern, $replacement, $str);
	return file_put_contents($configfile, $str);
}






function admin_tpl($template = 'index')
{
    $template = 'a_'.$template;
	$compiledtplfile = TPL_CACHEPATH.$template.'.tpl.php';
	if(TPL_REFRESH && (!file_exists($compiledtplfile) || @filemtime(TPL_ROOT.$template.'.html') > @filemtime($compiledtplfile)))
	{
		require_once './inc/template.func.php';
		template_compile($template);
	}
	return $compiledtplfile;
}

?>